package com.lobstar.xrpc.common.handler;

import java.nio.charset.Charset;
import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.lobstar.xrpc.common.po.SMessage;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;

public class SMessageDecoder extends MessageToMessageDecoder<ByteBuf>{
	static ObjectMapper mapper = new ObjectMapper();
	@Override
	protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
		SMessage message = mapper.readValue(msg.toString(Charset.forName("utf-8")), SMessage.class);
		out.add(message);
	}
}
